-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: revalidate cached members on GUILD_CREATE #9676
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
Both invalid GuildMembers and missing GuildMembers is not ideal. The other question is when is the
Or will reconnecting for example also trigger it? |
After full reconnect it will be triggered too, but then you also could have missed members leaving and presences being updated during the reconnect. So the same issue remains. The „fix“ for what you describe as problem here would be to fetch all members in guildCreate event and have a ready event that doesn’t run once but with on on every ready that does that for guilds you need it in. There’s no way for discord.js to validate the cache against what exists on discord other than replacing it completely in those cases. |
Yes, a "fix" as there is normally nothing else that will re-fetch the guild members, leaving the cache in an invalid state, without any obvious signs/warnings. This can lead to very weird, random seeming and even frustrating behaviour. Missed presence updates are also not a worry since this problem only occurs when there is no |
According to the Discord docs regarding the `GUILD_CREATE` event: If your bot does not have the `GUILD_PRESENCES` Gateway Intent, or if the guild has over 75k members, **members and presences returned in this event will only contain your bot and users in voice channels**.
And now you introduced a rather breaking change by fetching all members there. Which discord.js never does, it‘s upon the library user to decide whether they want to fetch all members or not. As already stated, the premise of your PR is wrong. If you need all members fetched you can do so yourself by listening to the respective event and fetching them again on a reconnect. It’s not the job of the library to do that for you. |
Your right, what I did here does not make much sense. |
If I am seeing this right though the GUILD_CREATE handler let guild = client.guilds.cache.get(data.id);
if (guild) {
if (!guild.available && !data.unavailable) {
// A newly available guild
guild._patch(data);
}
} else {
// A new guild
data.shardId = shard.id;
guild = client.guilds._add(data);
if (client.ws.status === Status.Ready) {
/**
* Emitted whenever the client joins a guild.
* @event Client#guildCreate
* @param {Guild} guild The created guild
*/
client.emit(Events.GuildCreate, guild);
}
} will not update the guild if a full reconnect occurs and the GUILD_CREATE's are sent again, since the guild would never have been marked as unavailable? |
Let's say someone did want to keep the members fetched. |
According to the Discord docs regarding the
GUILD_CREATE
event:If your bot does not have the
GUILD_PRESENCES
Gateway Intent, or if the guild has over 75k members, members and presences returned in this event will only contain your bot and users in voice channels.Please describe the changes this PR makes and why it should be merged:
This removes the line of code that clears the guild's members cache in
_patch()
(which is called by theGUILD_CREATE
event handler) to save the cached members in the event that you do not have theGUILD_PRESENCES
Gateway Intent, or if the guild has over 75k members and Discord sends aGUILD_CREATE
event for whatever reason.Status and versioning classification: